package vip.meeet.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@Component
public class AsyncComponent {

    @Async
    public String doSomething(String name) throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        return "Hello " + name;
    }

    @Async
    public Future<String> getAsyncResult(String name) throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        return new AsyncResult<>("getAsyncResult:Hello " + name) ;
    }

    @Async
    public void printName(String name) throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        System.out.println("printName:Hello " + name);
    }
}
